using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DTGH : MonoBehaviour
{
    public int[] Row0 = new[] { 9, 8, 6 };
    public int[] Row1 = new[] { 2, 3, 7 };
    public int[] Row2 = new[] { 4, 3, 1 };


    // Update is called once per frame
    void OnGUI()
    {
        if (GUILayout.Button("1"))
        {
            Algorithm1();
        }
    }

// p[i][j] = min(p[i-1][j], p[i][j-1]) + a[i][j]
// p[0][0] = a[0][0]
    void Algorithm1()
    {
        int[][] mat = new[] { Row0, Row1 };
        int[][] path = mat;
        for (int i = 0; i < mat.Length; i++)
        {
            for (int j = 0; j < mat[i].Length; j++)
            {
                int left = i > 0 ? path[i - 1][j] : 0;
                int up = j > 0 ? path[i][j - 1] : 0;
                path[i][j] = Math.Min(left, up) + mat[i][j];
            }
        }

        Debug.Log(path[mat.Length - 1][path[mat.Length - 1].Length - 1] + path[0][0]);
    }
}
